"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const koa_router_1 = __importDefault(require("koa-router"));
const BingTile_1 = __importDefault(require("../lib/GISServer/WMTSTile/BingTile"));
const TianDiTu_1 = __importDefault(require("../lib/GISServer/WMTSTile/TianDiTu"));
const mapServices = new koa_router_1.default({ prefix: '/mapServices' });
mapServices
    .get('/BingMaps/WMT/:z/:x/:y.jpeg', async (ctx) => {
    ctx.set('Content-Type', 'image/jpeg');
    const z = ctx.params.z;
    const x = ctx.params.x;
    const y = ctx.params.y;
    let [err, buffer] = await BingTile_1.default.getTileFileBufferByXYZ(x, y, z);
    ctx.status = 200;
    ctx.body = buffer;
})
    .get('/tianditu-wmts/:mapType/:TileMatrix/:TileCol/:TileRow.png', async (ctx) => {
    const { mapType, TileMatrix, TileCol, TileRow } = ctx.params;
    let [err, buffer] = await TianDiTu_1.default.getTileFileBuffer(mapType, TileMatrix, TileCol, TileRow);
    if (buffer) {
        ctx.set('Content-Type', 'image/png');
        ctx.body = buffer;
    }
    else {
        ctx.status = 422;
        ctx.set('Content-Type', 'application/json;charset=utf-8');
        ctx.body = err;
        console.warn('代理 天地图 瓦片失败', mapType, TileMatrix, TileCol, TileRow);
    }
});
exports.default = mapServices;
